import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:leader_doctor_flutter/common/data/app.dart';
import 'package:leader_doctor_flutter/common/http/api.dart';
import 'package:leader_doctor_flutter/common/http/http_client.dart';
import 'package:leader_doctor_flutter/common/utils/date_utils.dart';
import 'package:leader_doctor_flutter/common/utils/string_utils.dart';
import 'package:leader_doctor_flutter/common/widget/comm_widget.dart';
import 'package:leader_doctor_flutter/styles/colors.dart';
import 'package:leader_doctor_flutter/ui/wallet/model/new_order.dart';

/// @Author lixiaobin
/// @Date 2024/2/4
/// @Description 交易详情
class IncomeDetailPage extends StatefulWidget {
  const IncomeDetailPage({super.key, required this.subOrderNo});

  final String subOrderNo;

  @override
  State<IncomeDetailPage> createState() => _IncomeDetailPageState();
}

class _IncomeDetailPageState extends State<IncomeDetailPage> {
  NewOrder? _order;

  @override
  void initState() {
    super.initState();
    _findWalletDetail();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: CommWidget.getCommAppbar(context),
        body: Container(
            color: ColorRes.colorf7f7f7,
            child: Column(children: [
              SizedBox(height: 20.w),
              Text('￥${StringUtils.formatNumber(_order?.totalFee)}',
                  textAlign: TextAlign.center,
                  style: TextStyle(
                    fontSize: 16.sp,
                    color: ColorRes.colorff6666,
                  )),
              SizedBox(height: 20.w),
              Container(
                  margin: EdgeInsets.only(left: 14.w, right: 14.w),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(5.w),
                    color: ColorRes.white,
                  ),
                  child: Column(children: [
                    _buildItemView(
                        '交易类型', _order?.sysOrder?.orderTypeVal ?? ''),
                    _buildBuildLine(),
                    _buildItemView('业务编号', _order?.subOrderNo ?? ''),
                    _buildBuildLine(),
                    _buildItemView('交易日期',
                        MyDateUtils.format(_order?.payTime, 'yyyy-MM-dd')),
                    _buildBuildLine(),
                    _buildItemView(
                        '交易时间', MyDateUtils.format(_order?.payTime, 'HH:mm')),
                    _buildBuildLine(),
                    _buildItemView('付款人姓名', _order?.sysOrder?.userName ?? ''),
                    _buildBuildLine(),
                    _buildItemView('业务状态', '交易成功'),
                  ]))
            ])));
  }

  Widget _buildBuildLine() {
    return CommWidget.buildLine(
        margin: EdgeInsets.only(left: 14.w, right: 14.w));
  }

  Widget _buildItemView(String title, String value) {
    return Container(
        height: 45.w,
        margin: EdgeInsets.only(left: 12.w, right: 12.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(title,
                textAlign: TextAlign.center,
                style: TextStyle(
                  fontSize: 14.sp,
                  color: ColorRes.colorbdbdbd,
                )),
            Text(value,
                textAlign: TextAlign.center,
                style: TextStyle(
                  fontSize: 14.sp,
                  color: ColorRes.color333333,
                ))
          ],
        ));
  }

  /// 收入明细
  _findWalletDetail() async {
    var response = await HttpClient.post(HttpRequest(Api.findWalletDetail,
        body: {'subOrderNo': widget.subOrderNo ?? ''}));
    var serviceResult =
        ServiceResult<NewOrder>(response, (map) => NewOrder.fromJson(map));
    if (serviceResult.success) {
      _order = serviceResult.responseBody;
      setState(() {});
    }
  }
}
